<template>
    <div>
        <yd-cell-group>
            <yd-cell-item>
                <span slot="left">手机号码：</span>
                <yd-input
                    slot="right"
                    v-model="phone"
                    regex="mobile"
                    placeholder="请输入手机号码"
                ></yd-input>
            </yd-cell-item>

        </yd-cell-group>
        <div
            class="button"
            @click="poshData"
        >
            保存信息
        </div>
    </div>
</template>
<script>
export default {
    name: "userInfo",
    data() {
        return {
            name: '',
            phone: ''
        };
    },
    methods: {
        // 方法

        poshData() {
            let myreg = /^[1][0-9][0-9]{9}$/;
            if (!myreg.test(this.phone)) {
                this.$dialog.toast({
                    mes: '请输入正确的手机号',
                    timeout: 1500,
                });
                return;
            }
            let params = {
                type: 'main',
                member_id: localStorage.getItem('token'),
                user_phone: this.phone
            };
            this.$post("/wz_api/member/save", params)
                .then(res => {
                    if (res.code === 20000) {
                        this.$dialog.toast({
                            mes: '修改成功',
                            timeout: 1500,
                            icon: 'success',
                            callback: () => {
                                this.$router.back(-1)
                            }
                        });
                    } else {
                        this.$dialog.toast({
                            mes: res.msg,
                            timeout: 1500,
                        });
                    }
                })
                .catch(err => { });
        },
        getUserInfo() {
            let params = {
                member_id: localStorage.getItem('token'),
            };
            this.$post("/wz_api/member/detailByMain", params)
                .then(res => {
                    if (res.code === 20000) {
                        this.phone = res.data.user_phone
                    }
                })
                .catch(err => { });
        }
    },
    beforeCreate() {
        document.querySelector("body").setAttribute("style", "background-color:#e1deff");
    },
    created() {
        // 实例创建完成
        this.getUserInfo();
    },
};
</script>
<style lang="less" scoped>
.button {
    position: fixed;
    bottom: 50px;
    left: 50%;
    margin-left: -150px;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 300px;
    height: 50px;
    border-radius: 25px;
    font-size: 16px;
    color: #ffffff;
    background-image: linear-gradient(45deg, #827cff 0%, #4a57ff 100%);
}
</style>